package com.bbex.service.impl;

import com.bbex.mapper.RankDao;
import com.bbex.service.RankingService;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

@Service
public class RankingServiceImpl implements RankingService {
@Autowired
private RankDao rankDao;


    @Override
    public List<Map> getTeamRankNum() {
        List<Map>list=  rankDao.getTeamRankNum();
        BigDecimal team=BigDecimal.ZERO;
        for (int i = 0; i <list.size(); i++) {
            BigDecimal num=new BigDecimal(list.get(i).get("rankNum").toString());
            team=team.add(num);
        }

        for (int i = 0; i <list.size() ; i++) {
            BigDecimal num=new BigDecimal(list.get(i).get("rankNum").toString());
            BigDecimal scale=num.divide(team,4,BigDecimal.ROUND_HALF_UP);
            String scalely=scale.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"%";
            list.get(i).put("scalely",scalely);
        }
        return list;
    }


    @Override
    public List<Map> getPushRankNum() {
        List<Map>list=  rankDao.getPushRankNum();
        BigDecimal person=BigDecimal.ZERO;
        for (int i = 0; i <list.size(); i++) {
            BigDecimal num=new BigDecimal(list.get(i).get("rankNum").toString());
            person=person.add(num);
        }

        for (int i = 0; i <list.size() ; i++) {
            BigDecimal num=new BigDecimal(list.get(i).get("rankNum").toString());
            BigDecimal scale=num.divide(person,4,BigDecimal.ROUND_HALF_UP);
            String scalely=scale.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).toString()+"%";
            list.get(i).put("scalely",scalely);
        }
        return list;
    }

    @Override
    public Map getCmyInfo(String userId) {
        Map map =new HashMap();
        List<Map> inviteList=rankDao.getInviteInfo(userId);
        List<Map> pushList=rankDao.getPushInfo(userId);
        Map recomNum=rankDao.getRecomNum(userId);
        map.put("inviteList",inviteList);
        map.put("pushList",pushList);
        map.put("teamNum",recomNum.get("teamNum"));
        map.put("pushNum",recomNum.get("pushNum"));
        return map;
    }


}
